package com.tanhua.server.controller;

import com.tanhua.server.service.TestSoulService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

@Slf4j
@RequestMapping
@RestController
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    //测灵魂-问卷列表
    @GetMapping("/testSoul")
    public ResponseEntity<Object> showQuestion() throws InvocationTargetException, IllegalAccessException {
        return testSoulService.showQuestion();
    }

    //测灵魂-提交问卷
    @PostMapping("/testSoul")
    public ResponseEntity<Object> commit(@RequestBody Map<String,Object> answers){
        List<Map<String,String>> list = (List<Map<String,String>>) answers.get("answers");
        log.info("list : " + list);
        return testSoulService.commit(list);
    }

    //测灵魂-查看结果
    @GetMapping("/testSoul/report/{id}")
    public ResponseEntity<Object> showReport(@PathVariable("id") String id) throws InvocationTargetException, IllegalAccessException {
        return testSoulService.showReport(id);
    }
}
